import {defineStore} from "pinia"
const useCounterStore=defineStore("counter",{
  state:()=>{
    return {
      count:0
    }
  },
  getters: {
    oddOrEven(state){
      return state.count%2===1?'奇数':"偶数"
    }
  },
  actions: {
    increament(num){
      this.count+=num
    },
    decreament(num){
      this.count-=num
    },
    increamentIfOdd(num){
      if(this.count%2===1){
        this.increament(num)
      }
    },
    increamentAsync(num){
      setTimeout(()=>{
        this.increament(num)
      },1000)
    }
  },
  persist:true
})
export default useCounterStore